<template>
<div>
    <div style="margin-left: 20px;">
    <h3>新增代码仓库</h3>
    </div>
    <el-form style="width:70%" :model="form" :rules="rules" ref="form" label-width="120px" class="demo-ruleForm">
        <el-form-item label="代码仓库名称" prop="name">
          <el-input class="taskAdd-row-title" placeholder="请输入内容" size="medium" v-model="form.name" clearable></el-input>
        </el-form-item>
        <el-form-item label="代码仓库路径" prop="gitUrl">
          <el-input class="taskAdd-row-title" placeholder="代码仓库路径" size="medium" v-model="form.gitUrl" clearable></el-input>
        </el-form-item>
        <el-form-item  label="负责人" style="margin-bottom:0px">
             <selectRoleTwo type='warehouse' selectType='singleChoice'  style="width:100%" @selectsuccess='selectsuccess'></selectRoleTwo>
        </el-form-item>
        <el-form-item label='简介'>
            <el-input type="textarea" :rows="5" placeholder="请输入内容" v-model="form.content"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('form')">立即创建</el-button>
            <el-button @click="resetForm">取消</el-button>
        </el-form-item>
    </el-form>
</div>
</template>
<script>
 import { EventBus } from '@/api/eventbus'
import {save}from'@/api/git'
import quillEditor from '@/components/quillEditor/index'
 import multipleChoiceTags from '@/components/select/multipleChoiceTags'
  import selectRoleTwo from '@/components/screen/selectRoleTwo'
 export default({
     components: {
       quillEditor,
       selectRoleTwo
     },
     data () {
         return {
             form:{
               name:"",
               gitUrl:"",
               content:"",
               masterUserId:"",
             },
               options: [{
          value: '选项1',
          label: 'Java'
        }, {
          value: '选项2',
          label: 'C'
        }, {
          value: '选项3',
          label: 'C++'
        }, {
          value: '选项4',
          label: 'python'
        }, {
          value: '选项5',
          label: 'Edit'
        }],
             taskTitle:"",
             rules: {
                 name: [
                     { required: true, message: '请输入仓库名称', trigger: 'blur' },
                     ],
                 gitUrl: [
                     { required: true, message: '请输入仓库地址', trigger: 'blur' },
                     ],
            },
         }
     },
     methods: {
         selectsuccess(data){
           this.form.masterUserId=data[0].userId
         },
        submitForm(form){
          let params=new URLSearchParams()
          params.append('projId',this.$route.query.id)
          // this.form.projId=this.$route.query.id
          this.$refs[form].validate((valid) => {
          if (valid) {
               save(this.form,params).then(res=>{
                     EventBus.$emit('git-add',res.data)
              this.$store.dispatch('tagsView/delView', this.$route).then(({ visitedViews }) => {
                  this.$router.go(-1)
                })// 关闭当前tab回到列表
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });

         },
         resetForm(){
           this.$store.dispatch('tagsView/delView', this.$route).then(({ visitedViews }) => {
                  this.$router.go(-1)
              })// 关闭当前tab回到列表
         }
     }
 })
</script>
 <style scoped>
 .avatar{
     border-radius: 50%;
     width: 30px;
     /* height: 30px; */
 }
 .milepostselect{
     display: flex;
     align-items: center;
     margin-bottom: 20px;
     /* height: 50px; */
     /* background-color: blanchedalmond; */
     justify-content: space-between;
 }
 .milepostselect_div{
      display: flex;
     align-items: center;
 }
 .milepstdate{
     display: flex;
     width: 100%;
 }
</style>
